#define _CRT_SECURE_NO_WARNINGS 1

#include <queue>
class Solution {
public:
    bool ret = true;
    int _IsBalanced_Solution(TreeNode* proot, int height)
    {
        if (proot == nullptr) return 0;

        int left = _IsBalanced_Solution(proot->left, height) + 1;
        int right = _IsBalanced_Solution(proot->right, height) + 1;

        if (abs(left - right) > 1) ret = false;
        return max(left, right);
    }

    bool IsBalanced_Solution(TreeNode* pRoot) {
        if (pRoot == nullptr) return ret;
        int height = 1;
        TreeNode* pcur = pRoot;
        while (pcur->left)
        {
            height++;
            pcur = pcur->left;
        }
        _IsBalanced_Solution(pRoot, height);
        return ret;
    }
};